<?php
/**
 * Created by PhpStorm.
 * User: function
 * Date: 2018-05-02
 * Time: 18:01
 */

namespace app\admin\controller;
use app\common\controller\Admin;
use app\common\logic\InfoLogic;
class Info extends Admin
{
    public function index()
    {
        
        $logic = new InfoLogic();
        $params = paramForm();
        
        if (\think\Request::instance()->isAjax()) {
            $params['paginate'] = true;
            $logic->setValue('with','user,agree,cat');
            
            if (isset($params['title'])){
                $params['title'] = array('like','%'.$params['title'].'%');
            }
            
            //申请时间
            if(isset($params['start_time'])&&isValid($params['start_time'])){
                
                $startTime = strtotime($params['start_time']);
                if(!isValid($startTime)){
                    error('开始时间格式错误');
                }
                
                if(isset($params['end_time'])&&isValid($params['end_time'])){
                    
                    $endTime = strtotime($params['end_time'])+86400;
                    if(!isValid($endTime)){
                        error('截止时间格式错误');
                    }
                    
                }else{
                    $endTime = time();//如果不传就是获取当天的
                }
                
                $filter['create_time'] = array(array('EGT',$startTime),array('ELT',$endTime),'and');
                
            }
            
            
            $lists = $logic->getList($params);
            
            success($lists);
        } else {
            return $this->fetch();
        }
        
    }
    
    public function taggleStatus($id,$status){
        $logic = new InfoLogic();
        $info = $logic->findModel($id);
        $info->status = $status;
        $info->isUpdate()->save();
        $this->success('操作成功','/info/index');
    }
}